//
//  LoginVContro.m
//  ZY
//
//  Created by 高永杨 on 2017/3/3.
//  Copyright © 2017年 zhongchuang. All rights reserved.
//

#import "LoginVContro.h"
#import <AFNetworking.h>
#import "MainViewController.h"
#import "AppDelegate.h"
#import "RegisnVC.h"
#import "Singleton.h"
@interface LoginVContro ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *password;

@property (weak, nonatomic) IBOutlet UIButton *sureBut;

@end

@implementation LoginVContro

- (void)viewDidLoad {
    [super viewDidLoad];
    UIControl *control = [[UIControl alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [control addTarget:self action:@selector(clikResignKeyBord) forControlEvents:UIControlEventTouchUpInside];
    [self.view insertSubview:control atIndex:0];
    self.navigationController.navigationBar.hidden = YES;
    // Do any additional setup after loading the view from its nib.
    //监听当键盘将要出现时
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
-(void)clikResignKeyBord
{
[UIView animateWithDuration:0.5 animations:^{
    self.view.y = 0;
}];
    [self.view endEditing:YES];
}

//当键盘出现
- (void)keyboardWillShow:(NSNotification *)notification
{
    //获取键盘的高度
    NSDictionary *userInfo = [notification userInfo];
    NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [value CGRectValue];
    int height = keyboardRect.size.height;
    GYYLog(@"------%f",(self.sureBut.y+self.sureBut.height));
    if (height>GyyScreenH-(self.sureBut.y+self.sureBut.height)) {
        GYYLog(@"-----%f",GyyScreenH-(self.sureBut.y+self.sureBut.height));
        [UIView animateWithDuration:1 animations:^{
            self.view.y = -(height-(GyyScreenH-(self.sureBut.y+self.sureBut.height)))-10;
        }];
    }
}
- (IBAction)forgetPassword:(UIButton *)sender {
    
}

- (IBAction)loginClick:(UIButton *)sender {
 
    MainViewController *mainV = [[MainViewController alloc]init];
    [Singleton sharedSimple].loginVC = self;
    [[UIApplication sharedApplication].delegate window].rootViewController = mainV;
    return;
    if ([self.userName.text isEqualToString:@""]||[self.password.text isEqualToString:@""]) {
        [SVProgressHUD showErrorWithStatus:@"输入框的内容不能为空"];
        return;
    }
    [SVProgressHUD showWithStatus:@"正在登录中,请稍后"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSMutableDictionary *diction = [NSMutableDictionary dictionary];
    [diction setValue:@"28" forKey:@"opt"];
    [diction setValue:self.userName.text forKey:@"name"];
    [diction setValue:self.password.text forKey:@"pwd"];
    [manager POST:GolobaUrl parameters:diction progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        MainViewController *mainV = [[MainViewController alloc]init];
        [[UIApplication sharedApplication].delegate window].rootViewController = mainV;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [SVProgressHUD showErrorWithStatus:@"请求超时,请检查网络"];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    }];
}
//- (IBAction)sureButt:(UIButton *)sender {
//    MainViewController *mainV = [[MainViewController alloc]init];
//    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
//    [dict setValue:@"28" forKey:@"opt"];
//    [dict setValue:self.userName.text forKey:@"name"];
//    [dict setValue:self.password.text forKey:@"pwd"];
//    [[AFHTTPSessionManager manager]GET:loginUrl parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//          [[UIApplication sharedApplication].delegate window].rootViewController = mainV;
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        
//    }];
//  
//}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self clikResignKeyBord];
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)goToRegisn:(UIButton *)sender {
    
    RegisnVC *gisnV = [[RegisnVC alloc]init];
    [self presentViewController:gisnV animated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
